package com.xyf.sys.controller;

import com.xyf.sys.domain.SysProduct;
import com.xyf.sys.service.IProductService;
import com.xyf.sys.util.R;
import com.xyf.sys.vo.ProductListRequestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author R-H
 * @Date 2024/4/151705
 * @Description
 */
@RestController
@RequestMapping("/product")
@Slf4j
@Api(tags = "商品管理")
public class ProductController {

    @Autowired
    private IProductService productService;


    @ApiOperation("查询商品列表")
    @PostMapping("/list")
    public Object list(@RequestBody ProductListRequestVo body) {
        List<SysProduct> list = productService.list(body);
        return R.ok(list);
    }


    @ApiOperation("添加商品")
    @PostMapping("/add")
    public Object add(@RequestBody SysProduct product) {
        productService.add(product);
        return R.ok();
    }

    @ApiOperation("上架商品")
    @PostMapping("/up/{id}")
    public Object up(@PathVariable Long id) {
        return R.ok(productService.up(id));
    }

    @ApiOperation("下架商品")
    @PostMapping("/down/{id}")
    public Object down(@PathVariable Long id) {
        return R.ok(productService.down(id));
    }
}
